// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: 'kaoshitong-b82e77'
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()

  console.log(event);
  let balance = parseInt(event.balance);
  let num = parseInt(balance/10);
  let value = 0;

  switch(num+''){
    case '0':
    case '1':
      value = Math.round(Math.random()*5); 
      break;
    case '2':
    case '3':
      value = Math.round(Math.random()*4); 
      break;  
    case '4':
    case '5':
      value = Math.round(Math.random()*3); 
      break;
    case '6':
    case '7':
      value = Math.round(Math.random()*2); 
      break;  
    case '8':
      value = Math.round(Math.random()*1); 
    case '9':
      value = new Boolean(Math.round(Math.random()*1)) ? 0.01 : 0.02; 
      break; 
    default:    
      value = new Boolean(Math.round(Math.random()*1)) ? 0.01 : 0.02;        
  }

  return {
    value
  }
}